class Country < ActiveRecord::Base
  has_and_belongs_to_many :general_news_letters
  has_many :states
  has_many :profiles, :as => :reference
  belongs_to :currency
  
  def self.search_selector(search_name, page)
    items_per_page = count_record_per_page :countries
    order = "name"
    conditions_clauses = []
    conditions_options = []

    if !search_name.nil? && search_name != ""
      conditions_clauses << "upper(name) like upper(?)"
      conditions_options << "%#{search_name}%"
    end
    conditions = [conditions_clauses.join(" AND "), conditions_options].flatten

    @countries = paginate :per_page => items_per_page,:page => page, :conditions => conditions, :order => order
    return @countries
  end
end